home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9717 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: problem with types
  5. Date: 12 Mar 1996 22:05:56 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Mar12150556@qcd.lanl.gov>
  8. References: <Do5Mu9.6nv@lut.ac.uk>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: R.Sheikhan@lut.ac.uk's message of Tue, 12 Mar 1996 12:32:33 GMT
  13.  
  14. In article <Do5Mu9.6nv@lut.ac.uk>
  15. R.Sheikhan@lut.ac.uk (R.Sheikhan) writes:
  16.  
  17. R: Hi;
  18. R: When I use  int  to declare my variable type my programme works fine, but
  19. R: when I use long  it doesn't work. Every thing looks ok but I just can't
  20. R: figure out why. I would appreciate any help. 
  21. <snip>
  22. R:     printf(" LCM is %ld\n", LCM_Array(Numbers));
  23.  
  24. No declaration of LCM_Array is visible at this point, so the return
  25. value is assumed to be int. This is passed to printf which assumes it
  26. is a long (%ld). The former is your mistake (You should declare `long
  27. LCM_ARRAY();' at the top), the latter leads to undefined behaviour
  28. (i.e. the compiler can now do what it pleases with the code).
  29.  
  30. <snip>
  31. R: LCM_Array(Array)
  32.  
  33. No return type is defined here (i.e. you did not say `long
  34. LCM_Array(Array)': if you had, you still would have had a problem
  35. unless you declared it at the top, because previous implicit
  36. declaration above was `extern int LCM_Array();'), so it defaults to
  37. int.
  38.  
  39. <snip>
  40. R:     long loop_counter;
  41. <snip>
  42. R:         return sofar;
  43.  
  44. The variable sofar is converted to int and returned.
  45.  
  46. Cheers
  47. Tanmoy
  48. --
  49. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  50. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  51. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  52. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  53. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  54. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  55.